package cn.edu.ren.controller;

import cn.edu.ren.dao.IStudentDao;
import cn.edu.ren.pojo.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @PackageName: cn.edu.ren.controller
 * @ClassName: StudentController
 * @Description:
 * @author: RZS
 * @date: 2021/5/20  9:42
 */
@RestController
@RequestMapping("/stu")
public class StudentController {

    @Autowired
    private IStudentDao studentDao;

    // 查询全部数据
    @GetMapping("/sel_all")
    public List<Student> findAll(){
        // 调用jap提供的查询方法
        return studentDao.findAll();
    }

    // 根据用户名查询用户数据
    @GetMapping("/find_by_name")
    public Student findById(String username){
        System.err.println(studentDao.findByName(username).toString());
        return studentDao.findByName(username);
    }

    // 添加数据
    @PostMapping("/add")
    public List<Student> addStudent(Student student){
        studentDao.save(student);
        return findAll();
    }
}
